#ifndef __UTILS_H__
#define __UTILS_H__

#include "type.h"

class StringUtils {
  public:
    static int split(const std::string& input, const std::string& delimitor, std::vector<std::string>& output)
    {
      // default, we suppose that the separator has only 1 character
      if ( (delimitor.size() == 0) || (input.size() == 0) ) {
        return 0;
      }

      size_t lpos = 0;
      size_t pos = input.find_first_of(delimitor);

      if ( pos < 0 ) {
        return 0;
      }

      while (pos != std::string::npos) {
        if (pos != lpos)
          output.push_back(input.substr(lpos, pos - lpos));

        lpos = pos + delimitor.size(); // the second item can only be 1

        pos = input.find_first_of(delimitor, lpos);
      }

      if (lpos < input.length())
        output.push_back(input.substr(lpos, pos - lpos));

      return output.size();
    }
};


#endif
